package com.itheima.Demo;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Demo文件上传服务器端 {
    public static void main(String[] args) throws IOException {
        //创建对象;
        ServerSocket ss  = new ServerSocket(1314);
        //通过获取的对象连接客户端;
        Socket s = ss.accept();
        //创建输入流;
        BufferedInputStream is = new BufferedInputStream(s.getInputStream());
        //创建输出流;
        BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream("C:\\Users\\97622\\Desktop\\张梓墨复制照片.jpg"));
        //读取数据并写入数据;
        byte[] arr  = new byte[1024];
        int i ;
        while ((i=is.read(arr))!=-1){
            fos.write(arr);
        }
        //创建输出流;
        OutputStream os = s.getOutputStream();
        os.write("上传成功".getBytes());
        //关流

        s.close();
        fos.close();
        is.close();
    }
}
